Skip to content

fix(idempotency): apply jmespath_options to payload_validation_jmespath - #8474

Merged
leandrodamascena merged 3 commits into
aws-powertools:developfrom
Om-singhaI:fix/idempotency-payload-validation-jmespath-options
Sep 28, 2026
Merged

leandrodamascena merged 3 commits into
aws-powertools:developfrom
Om-singhaI:fix/idempotency-payload-validation-jmespath-options

Conversation

@Om-singhaI

Copy link
Copy Markdown
Contributor

Issue number: closes #8473

Summary

Changes

BasePersistenceLayer passes jmespath_options to the idempotency key search but not to the payload_validation_jmespath search in _get_hashed_payload. By default those options hold the Powertools functions, so powertools_json(), powertools_base64(), powertools_base64_gzip() and any custom function raised UnknownFunctionError in the validation expression.

save_inprogress hashes the payload before it writes the record. So every call failed with IdempotencyPersistenceLayerError and the handler never ran.

  • _get_hashed_payload now passes the same jmespath.Options as the key search.
  • New functional test with powertools_json(body) in both expressions. The same order replays the stored response, and a changed amount raises IdempotencyValidationError.
  • New functional test for a function from custom jmespath_options used in payload_validation_jmespath.

User experience

Before: payload_validation_jmespath="powertools_json(body).amount" fails every call with Unknown function: powertools_json().

After: the handler runs, and a repeat request with a changed amount raises IdempotencyValidationError.

Testing:

  • Both new tests in tests/functional/idempotency/_boto3/test_idempotency.py fail on develop with Unknown function errors and pass here.
  • tests/functional/idempotency/_boto3, tests/functional/idempotency/_pydantic and tests/unit/idempotency: 133 passed.
  • ruff format --check and ruff check pass on both files. mypy is clean on persistence/base.py.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

The idempotency key search passes jmespath_options (by default the
Powertools functions like powertools_json), but the payload validation
search didn't pass any options. Any payload_validation_jmespath using
powertools_json, powertools_base64, powertools_base64_gzip or a custom
function raised "Unknown function" when hashing the payload, so every
invocation failed with IdempotencyPersistenceLayerError before the
handler ran.

Pass the same options to the payload validation search.
@Om-singhaI
Om-singhaI requested a review from a team as a code owner September 18, 2026 20:45
@Om-singhaI
Om-singhaI requested a review from hjgraca September 18, 2026 20:45
@boring-cyborg

boring-cyborg Bot commented Sep 18, 2026

Copy link
Copy Markdown

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@boring-cyborg boring-cyborg Bot added the tests label Sep 18, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 18, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 28, 2026
@sonarqubecloud

Copy link
Copy Markdown

@leandrodamascena leandrodamascena left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, @Om-singhaI, and thanks for the fix! Both expressions should honor the same JMESPath options. I pushed a regression test covering overridden native functions, including the compatibility case where an unchanged payload is rejected because an older record’s hash was generated with the native function. All 135 idempotency tests pass locally.

@mergify

mergify Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@codecov

codecov Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.80%. Comparing base (1a6c4c6) to head (8f19c83).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8474   +/-   ##
========================================
  Coverage    96.80%   96.80%           
========================================
  Files          310      310           
  Lines        15541    15541           
  Branches      1354     1354           
========================================
+ Hits         15044    15045    +1     
  Misses         361      361           
+ Partials       136      135    -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leandrodamascena
leandrodamascena merged commit 54ed27d into aws-powertools:develop Sep 28, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: payload_validation_jmespath ignores jmespath_options, so powertools_json() raises Unknown function

2 participants